package main

import (
	"context"
	"fmt"
	"time"

	clientv3 "go.etcd.io/etcd/client/v3"
)

func main() {
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"10.0.0.11:2379"},
		DialTimeout: 5 * time.Second,
	})
	if err != nil {
		fmt.Println(err)
		return
	}

	// 创建OP
	putOp := clientv3.OpPut("/cron/jobs/job8", "same one")

	// 执行OP
	opResp, err := cli.Do(context.TODO(), putOp)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("写入Revision:", opResp.Put().Header.Revision)

	// 创建OP
	getOp := clientv3.OpGet("/cron/jobs/job8")

	opResp, err = cli.Do(context.TODO(), getOp)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("数据：", string(opResp.Get().Kvs[0].Value))

}
